/*
 * Copyright (c) 2018.
 * By:kaihangchen
 * E-mail:cmxds@hotmail.com
 */

package cn.cmxds.store.adapter;

import android.support.v7.widget.RecyclerView;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;

import java.util.List;

import cn.cmxds.store.R;
import cn.cmxds.store.bean.HotResultsBean;


public class MyHotAdapter extends RecyclerView.Adapter<MyHotAdapter.MyViewHolder>{
    private Context context;
    private List<HotResultsBean> list;

    public MyHotAdapter(Context context, List<HotResultsBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.template_hot_cardview, null);
        MyViewHolder myViewHolder = new MyViewHolder(view);

        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        ViewGroup.LayoutParams params = holder.iv_recy.getLayoutParams();
        if(position == 0){
            params.height = 200;
        }else{
            params.height = 400;
        }
        holder.iv_recy.setLayoutParams(params);
        Picasso.with(holder.iv_recy.getContext()).load(list.get(position).getUrl()).into(holder.iv_recy);
        holder.tv_recy.setText(list.get(position).getType());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder{

        ImageView iv_recy;
        TextView tv_recy;

        public MyViewHolder(View itemView) {
            super(itemView);
            iv_recy = (ImageView) itemView.findViewById(R.id.iv_recy);
            tv_recy = (TextView) itemView.findViewById(R.id.tv_recy);

        }
    }
    public void loadMore(List<HotResultsBean> li){
        for (HotResultsBean str : li){
            list.add(str);
        }
        //更新界面
        notifyDataSetChanged();

    }
    public void refreshMore(List<HotResultsBean> li){
        for (HotResultsBean str : li){
            list.add(0,str);
        }
        //更新界面
        notifyDataSetChanged();

    }
}
